package com.designPattern.dynamicProxy;

import java.lang.reflect.Method;


public class TankProxy {
	@SuppressWarnings("unchecked")
	public static <T> T getBean(final Object tank) throws Exception{
		return (T)Proxy.newProxyInstance(tank.getClass().getInterfaces()[0], new InvocationHandler() {
			
			@Override
			public void invoke(Object o, Method m) {
				long start = System.currentTimeMillis();
				System.out.println("start:"+start);
				try {
				m.invoke(tank, new Object[]{});
				} catch (Exception e) {
				                     e.printStackTrace();
				}
				 long end = System.currentTimeMillis();
				System.out.println("end:"+end);
				System.out.println("time:"+(end-start));
			}
		});
	}
}
